using UnityEngine;

namespace VoxelEngine.Utils
{
	public class PlaySound : MonoBehaviour
	{
		[SerializeField]
		private bool _playOnStart;

		[SerializeField]
		private bool _playOnEnable;

		[SerializeField]
		private bool _playOnDisable;

		[SerializeField]
		private bool _playOnDestroy;

		[SerializeField]
		private bool _ignoreFirstEnable;

		[SerializeField]
		private float _volume = 1f;

		[SerializeField]
		private AudioClip _audioClip;

		private bool _isFirstEnable = true;

		private void Start()
		{
			if (_playOnStart)
			{
				SoundManager.Instance.PlaySoundEffect(_audioClip, _volume);
			}
		}

		private void OnEnable()
		{
			if (_ignoreFirstEnable && _isFirstEnable)
			{
				_isFirstEnable = false;
			}
			else if (_playOnEnable)
			{
				SoundManager.Instance.PlaySoundEffect(_audioClip, _volume);
			}
		}

		private void OnDisable()
		{
			if (_playOnDisable)
			{
				SoundManager.Instance.PlaySoundEffect(_audioClip, _volume);
			}
		}

		private void OnDestroy()
		{
			if (_playOnDestroy)
			{
				SoundManager.Instance.PlaySoundEffect(_audioClip, _volume);
			}
		}
	}
}
